/*******************************************************************************
*  file    : qloggerengine.hpp
*  created : 01.05.2013
*  author  : 
*******************************************************************************/

#ifndef QLOGGERENGINE_HPP
#define QLOGGERENGINE_HPP

#include "qloggerconf.hpp"
#include <QTime>
#include <QHash>
#include <QSharedPointer>
#include "qloggerevent.hpp"
#include "qloggerappender.hpp"

class QLogger;
class QLoggerAppender;

class QLOGGER_DECL QLoggerEngine
{

private:
    friend class QLoggerAppender;
    friend class QLogger;
    QHash<QString, QLogger *> loggers;
    QList<QSharedPointer<QLoggerAppender> > appenders_;
    QTime startTime;

private:
    static QLoggerEngine &handle()
    {
        static QLoggerEngine hInstance;
        if (hInstance.startTime.isNull())
            hInstance.startTime.start();
        return hInstance;
    }
    bool hasAppender(QLoggerAppender* a) const;
    QSharedPointer<QLoggerAppender> appender(QLoggerAppender* a);
    ~QLoggerEngine ();

public:
    int elapsed();

    static QLogger*    getLogger (const QString &moduleName);
    static const char* levelName (QLoggerLevel level);
};

#endif // QLOGGERENGINE_HPP
